package com.hyy.asm.server.handler;

import com.hyy.asm.message.GroupJoinRequestMessage;
import com.hyy.asm.message.GroupJoinResponseMessage;
import com.hyy.asm.server.session.GroupSessionFactory;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

@ChannelHandler.Sharable
public class GroupJoinRequestMessageHandler extends SimpleChannelInboundHandler<GroupJoinRequestMessage> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, GroupJoinRequestMessage msg) throws Exception {
        String groupName = msg.getGroupName();
        String username = msg.getUsername();
        GroupSessionFactory.getGroupSession().joinMember(groupName,username);
        GroupJoinResponseMessage groupJoinResponseMessage = new GroupJoinResponseMessage(true,username+"成功加入"+groupName);
        ctx.writeAndFlush(groupJoinResponseMessage);
    }
}
